#ifndef MEQTDEBUGMAIN_H
#define MEQTDEBUGMAIN_H

#if defined(WIN32) && defined(_DEBUG)
#include <stdlib.h>
#include <crtdbg.h>
#include <Windows.h>
#define _CRTDBG_MAP_ALLOC
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW

// Nur Leaks aus eigenem Code anzeigen
int reportHook(int reportType, char *message, int *returnValue)
{
	Q_UNUSED(reportType)
	Q_UNUSED(returnValue)

	static bool started = false;
	static int msgCount = 0;
	static int ignoredLeaks = 0;

	if (!started && strcmp(message, "Detected memory leaks!\n") == 0)
	{
		started = true;
		msgCount = 1;
		ignoredLeaks = 0;
	}
	else if (started && strcmp(message, "Object dump complete.\n") == 0)
	{
		started = false;
		TCHAR tmp[30];
		swprintf_s(tmp, TEXT("Ignored memory leaks: %i\n"), ignoredLeaks);
		OutputDebugString(tmp);
	}

	if (started)
	{
		if (strstr(message, ".cpp") || strstr(message, ".h"))
			msgCount = 0;
		else if (++msgCount > 3)
		{
			if ((msgCount - 4) % 3 == 0)
				++ignoredLeaks;

			// Ignore
			return 1;
		}
	}

	// Output
	return 0;
}
#endif

#endif // MEQTDEBUGMAIN_H